#!/bin/bash

# only info, compile it under windows, no cross compiling

cat << EOF

modify "mkspecs\win32-g++\qmake.conf" file,
add "-Wl,--export-all-symbols" to QMAKE_LFLAGS

build qt with following commands :

shell> configure -release -opensource -platform win32-g++ -no-dsp -no-vcproj -no-webkit -nomake examples -nomake demos
shell> mingw32-make

when use QT4, set following environ values :
PATH      : add qt tools ( such as qmake ) bin directory to PATH
QTDIR     : set to root directory of qt4 source
QMAKESPEC : set to "win32-g++"

EOF


# apply the following patch :

cat << EOF

git b1b3bdabe50262405af5ffd094f333e8048bd2f7
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -68,6 +68,29 @@
 #   include "private/qcore_mac_p.h"
 #   include <CoreFoundation/CoreFoundation.h>
 #endif
+
+/* There is a conflict with some headers provided with gcc on windows and the
+ * mingw-w64 crt. They both provide a float.h
+ * The gcc version however does not have some defines that we need for qdtoa.
+ * In the event that we are using mingw-w64 headers, check if the first define
+ * we need is defined, if not define them
+ */
+#if defined(__MINGW64_VERSION_MAJOR) && !defined(_control87)
+extern "C" {
+// We want _mingw.h but we shouldn't include that directly
+#include <windows.h>
+_CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int unNew, unsigned int unMask);
+_CRTIMP unsigned int __cdecl __MINGW_NOTHROW _clearfp (void);	/* Clear the FPU status word */
+_CRTIMP unsigned int __cdecl __MINGW_NOTHROW _statusfp (void);	/* Report the FPU status word */
+#define _control87 _controlfp
+#define _clear87 _clearfp
+#define _status87 _statusfp
+#define	_MCW_DN	0x03000000  	/* Denormal control */
+#define	_MCW_EM	0x0008001F	/* Error masks */
+#define	_MCW_RC	0x00000300	/* Rounding */
+}
+#endif // __MINGW64_VERSION_MAJOR
+
 #include "private/qnumeric_p.h"
 
 #include <ctype.h>



git 6dc9873a56f8ab7f1f2d37e9f789faca38839c15
--- a/src/activeqt/container/qaxbase.cpp
+++ b/src/activeqt/container/qaxbase.cpp
@@ -1357,7 +1357,8 @@
 
 
 // There seams to be a naming problem in mingw headers
-#ifdef Q_CC_GNU
+// But not in mingw-w64
+#if defined(Q_CC_GNU) && !defined(__MINGW64_VERSION_MAJOR)
 #ifndef COAUTHIDENTITY
 #define COAUTHIDENTITY AUTH_IDENTITY
 #endif
--- a/src/activeqt/container/qaxwidget.cpp
+++ b/src/activeqt/container/qaxwidget.cpp
@@ -82,7 +82,8 @@
 // #define QAX_SUPPORT_BORDERSPACE
 
 // missing interface from win32api
-#if defined(Q_CC_GNU)
+// Not missing from mingw-w64
+#if defined(Q_CC_GNU) && !defined(__MINGW64_VERSION_MAJOR)
 #   if !defined(IOleInPlaceObjectWindowless)
 #       undef INTERFACE
 #       define INTERFACE IOleInPlaceObjectWindowless


EOF


# apply more patch

cat << EOF

src\3rdparty\javascriptcore\JavaScriptCore\runtime\Collector.cpp
add "&& !defined(__MINGW64_VERSION_MAJOR)" for aligned_malloc() aligned_free()

src\3rdparty\clucene\src\CLucene\config\repl_tchar.h
add "#define _TCHAR_DEFINED" after " #define TCHAR wchar_t" and " #define TCHAR char"

EOF


